/* jQuery for hide/show bottom bar */
jQuery(document).ready(function($) {
	/* Toggle to show/hide bottom bar */
	$("#msid-arrowtoggle").toggle(
		function(){
			$(this).removeClass("msid-rightarrows").addClass("msid-leftarrows");
			$("#msid-formarea").hide();
		},
		function(){
			$(this).removeClass("msid-leftarrows").addClass("msid-rightarrows");
			$("#msid-formarea").show();
		}
	);

	/* Auto position bottom bar */
	positionFooter();
	$(window)
		.scroll(positionFooterAnimate)
		.resize(positionFooter)
});

/* Auto position bottom bar during resize and scroll */
function positionFooter(){
	var winHeight = $(window).height();
	var barHeight = $("#msid-bottombar").height();
	var scrTop = $(window).scrollTop();

	$("#msid-bottombar").css({position: "absolute", top: (scrTop + winHeight - barHeight) + "px" });
};

function positionFooterAnimate(){
	var winHeight = $(window).height();
	var docHeight = $(document).height();
	var barHeight = $("#msid-bottombar").height();
	var scrTop = $(window).scrollTop();
	var viewLimit;

	$("#msid-bottombar").stop();

	if(docHeight < winHeight)
		viewLimit = winHeight - barHeight;
	else
		viewLimit = docHeight - barHeight;

	$("#msid-bottombar").animate({top: scrTop - barHeight + winHeight}, "slow");
};